local wdtx__analepticSkill = fk.CreateSkill {
  name = "wdtx__analeptic_skill",
}


wdtx__analepticSkill:addEffect("cardskill", {
  prompt = "#wdtx__analeptic_skill",
  max_turn_use_time = 1,
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card, extra_data)
    return Util.CanUseToSelf(self, player, card, extra_data) and
      ((extra_data and (extra_data.bypass_times or extra_data.analepticRecover)) or
      self:withinTimesLimit(player, Player.HistoryTurn, card, "analeptic", player))
  end,
  on_use = function(self, room, use)
    if use.extra_data and use.extra_data.analepticRecover then
      use.extraUse = true
    end
  end,
  on_effect = function(_, room, effect)
    local to = effect.to
    if effect.extra_data and effect.extra_data.analepticRecover then
      if to:isWounded() and not to.dead then
        room:recover({
          who = to,
          num = 1,
          recoverBy = effect.from,
          card = effect.card,
        })
      end
    else
      if room.logic.class.name == "wdtx_logic" and effect.card:getMark("@up_analep") > 0 and to.id > 0 then
        local Wdtx = room.logic.Wdtx
        local upcards = Wdtx:getCanUpCards(to:getCardIds("h"))
        if #upcards == 0 then room:doBroadcastNotify("ShowToast","手牌没有可升级") return end
        local seln = effect.card:getMark("@up_analep")
        -- p(table.map(upcards,function(id) return Fk:getCardById(id).name end))
        -- dbg()
        local success, dat = room:askToUseActiveSkill(to,{
          skill_name = "#wdtxFindUpCardsSkill",
          prompt = "#wdtxFindUpCardsSkill:::"..seln,
          no_indicate = true,
          extra_data = {target_cards = upcards, card_num = seln},
        })
        if success and dat and #dat.cards > 0 then
          Wdtx:upCardsByTmp(dat.cards)
        end
      end
      to.drank = to.drank + 1 + ((effect.extra_data or {}).additionalDrank or 0)
      room:broadcastProperty(to, "drank")
    end
  end
})


return wdtx__analepticSkill